package com.infoland.afanmall.base.activity;

import android.content.Context;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.AppGlideModule;

/**
 * Glide 工具类
 */
@GlideModule
public final class MyAppGlideModule extends AppGlideModule {
    /**
     * MemorySizeCalculator类通过考虑设备给定的可用内存和屏幕大小想出合理的默认大小.
     * * 通过LruResourceCache进行缓存。 * @param context * @param builder
     */
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        int memoryCacheSizeBytes = 1024 * 1024 * 100; // 100mb
        int diskCacheSizeBytes = 1024 * 1024 * 1000; // 500 MB
        builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
//        MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).setMemoryCacheScreens(3).build();
//        builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize()));

        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
    }

    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }
}